﻿using System.Collections.Generic;
using System.Linq;
using ESoft.DataAccess;
using ESoft.Helpers;
using ESoft.Locking;
using ESoft.Logging;
using ESoft.RabbitMQ;
using ESoft.Redis;
using Microsoft.AspNetCore.Mvc;
using SampleWeb.Data.Models;

namespace SampleWeb.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly IBaseReponsitory _baseReponsitory;
        private readonly IRedisService _redisService;
        private readonly IDistributeLock _distrubuteLock;
        private readonly IRabbitMQService _rabbitMQService;
        private readonly ILogging<ValuesController> _logging;

        public ValuesController(IBaseReponsitory baseReponsitory, IRedisService redisService, IDistributeLock distrubuteLock, IRabbitMQService rabbitMQService, ILogging<ValuesController> logging)
        {
            _baseReponsitory = baseReponsitory;
            _redisService = redisService;
            _distrubuteLock = distrubuteLock;
            _rabbitMQService = rabbitMQService;
            _logging = logging;
        }


        // GET api/values
        [HttpGet]
        public List<GGoodsEntity> Get()
        {
            _logging.Info("123");
            _rabbitMQService.Send(new TestPayload() { Id = StringHelper.GetId() }, "test01");
            //_zooKeeperService.CreatePersistentAsync("/test/test2", ByteConvertHelper.String2Bytes("hello")).Wait();
            //Console.WriteLine(Thread.CurrentThread.Name + "-todo");
            //_distrubuteLock.AcquireLock("k");
            var list = _baseReponsitory.FindAll<GGoodsEntity>().ToList();
            //_distrubuteLock.ReleaseLock("k");
            //Console.WriteLine(Thread.CurrentThread.Name + "-done");
            return list;
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
